<template>
  <van-nav-bar title="订单详情" left-arrow @click-left="back" />
  <section class="aui-flexView">
    <!-- 订单详细 -->
    <section class="aui-scrollView">
      <!-- 订单状态 -->
      <div class="aui-pay-change">
        <div class="aui-flex">
          <div class="aui-flex-box">
            <h3>{{ info.status_text }}</h3>
          </div>
          <div class="aui-pay-zfb">
            <img src="/assets/images/icon-zfb.png" alt="" />
          </div>
        </div>
      </div>

      <!-- 收货地址 -->
      <div class="aui-flex">
        <div class="aui-flex-add">
          <img :src="business.avatar_text" alt="" />
        </div>
        <div class="aui-flex-box">
          <h3>
            {{ info.address.consignee }} <em>{{ info.address.mobile }}</em>
          </h3>
          <p>{{ info.address.region_text }} {{ info.address.address }}</p>
        </div>
      </div>

      <!-- 订单商品 -->
      <div class="aui-commodity-bg" style="background: transparent">
        <div
          style="margin-bottom: 10px; background: #f5f5f5"
          v-for="item in info.detail"
          :key="item.id"
        >
          <div class="aui-flex">
            <div class="aui-commodity-img">
              <img :src="item.product.thumb_text" />
            </div>
            <div class="aui-flex-box">
              <h4 class="van-ellipsis">商品名称：{{ item.product.name }}</h4>
              <p>商品单价：￥{{ item.price }}</p>
              <span class="aui-barter-time">七天退换</span>
            </div>
            <div>
              <h5>￥{{ item.total }}</h5>
              <p class="aui-sml-text">X{{ item.pronum }}</p>
            </div>
          </div>

          <div style="text-align: right">
            <van-button
              type="primary"
              size="mini"
              v-if="info.status == '3'"
              @click="toPages(item.id)"
              >评价
            </van-button>
          </div>
        </div>
      </div>

      <!-- 总价 -->
      <div class="aui-cp-edu b-line">
        <div class="aui-flex aui-flex-ed">
          <div class="aui-flex-box" style="color: #333; font-size: 15px">
            订单总价<em style="color: #333">￥{{ info.amount }}</em>
          </div>
        </div>
      </div>

      <div class="divHeight b-line"></div>

      <!-- 订单详细内容 -->
      <div class="aui-flex aui-flex-text-sml b-line orderinfo">
        <div class="aui-flex-box">
          <p>
            <em>订单号:</em>
            {{ info.code }}
          </p>
          <p v-if="info.expressid">
            <em>配送物流: </em>
            {{ info.express_text }}
          </p>
          <p v-if="info.expressid">
            <em>物流单号:</em>
            {{ info.expresscode }}
          </p>
          <p>
            <em>下单时间:</em>
            {{ info.createtime }}
          </p>
          <p>
            <em>订单状态:</em>
            {{ info.status_text }}
          </p>
          <p>
            <em>订单备注:</em>
            {{ info.remark }}
          </p>
        </div>
      </div>
    </section>

    <footer class="aui-footer aui-footer-fixed">
      <div class="aui-footer-text-info" v-if="info.status > 0 && info.status != 4">
        <a href="javascript:;" class="aui-payment">申请退货</a>
      </div>
      <div class="aui-footer-text-info" v-if="info.status == '2'">
        <a href="javascript:;" class="aui-payment">确认收货</a>
      </div>
    </footer>
  </section>
</template>
<script setup>
const { proxy } = getCurrentInstance();
const back = () => proxy.$router.push("/order/index");
let business = proxy.$cookies.get("business") ? proxy.$cookies.get("business") : {};
business = reactive(business);
let orderid = proxy.$route.query.hasOwnProperty("orderid")
  ? proxy.$route.query.orderid
  : 0;
orderid = ref(orderid);
const info = ref({
  address: {},
  detail: [],
});
onBeforeMount(() => {
  getInfoData();
});
const getInfoData = async () => {
  let result = await proxy.$POST({
    url: "/order/info",
    params: {
      orderid: orderid.value,
      busid: business.id,
    },
  });
  if (result && result.code == 1) {
    info.value = result.data;
  }
};
const toPages = (id) => {
  proxy.$router.push({
    path: "/order/rate",
    query: { orderid: orderid.value, orderproid: id },
  });
};
</script>
<style>
@import url("/assets/css/info.css");
</style>
